<template>
	<el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="900px" @open="open" @close="close" top="10px" :append-to-body="true" :modal-append-to-body="true">
		<div style="padding-bottom:10px">
			<!-- 查询界面 -->
			<tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" :isDisplaySearch="false">
				<template slot="search">
					<el-form-item label="编号" prop="code">
						<el-input v-model.trim="queryParam.qry_code" placeholder="请输入编号" @keydown.enter.native="doQuery" clearable></el-input>
					</el-form-item>
					<el-form-item label="名称">
						<el-input v-model.trim="queryParam.qry_name" placeholder="请输入名称" @keydown.enter.native="doQuery" clearable></el-input>
					</el-form-item>
					<el-form-item label="有效" prop="qry_enabled" v-if="this.isShowQryEnabled">
						<el-select v-model="queryParam.qry_enabled" filterable>
							<el-option v-for="item in this.enabledList" :key="item.code" :label="item.name" :value="item.code" />
						</el-select>
					</el-form-item>
					<el-form-item label="部门类型" v-if="this.isProductline">
						<el-select v-model="queryParam.qry_depttype" filterable clearable>
							<el-option v-for="item in this.deptType" :key="item.code" :label="item.name" :value="item.code" />
						</el-select>
					</el-form-item>
				</template>
				<template slot="search">
					<el-button class="filter-item" type="primary" icon="el-icon-search" @click="doQuery">搜索</el-button>
					<el-button class="filter-item" type="primary" @click="clearRef">清空</el-button>
				</template>
			</tl-list-search>
			<!-- 列表界面 -->
			<div>
				<!-- 列表选择 -->
				<div class="table-alert-div" ref="selector">
					<el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
						<template slot="title">
							已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRows.length }}</a
							>项&nbsp;&nbsp;
							<a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
						</template>
					</el-alert>
				</div>
				<!--表格渲染-->
				<el-table class="tl-table" ref="mainTable" :height="tableHeight" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
					<el-table-column type="selection" width="55px" fixed="left" v-if="isSingleSelect === false"> </el-table-column>
					<el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
					<el-table-column prop="code" label="编号" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="name" label="名称" width="200px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<!-- <el-table-column prop="deptcodes" label="质量运营部门" width="150px" sortable="custom" sort-by="deptcodes" align="center" header-align="center"></el-table-column> -->
					<el-table-column prop="deptnames" label="质量运营部门" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<!-- <el-table-column prop="alertusercodes" label="提醒人" width="150px" sortable="custom" sort-by="alertusercodes" align="center" header-align="center"></el-table-column> -->
					<el-table-column prop="alertusernames" label="提醒人" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<!-- <el-table-column prop="qcusercodes" label="质量运营专员" width="150px" sortable="custom" sort-by="qcusercodes" align="center" header-align="center"></el-table-column> -->
					<el-table-column prop="qcusernames" label="质量运营专员" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<!-- <el-table-column prop="authorizationdeptcodes" label="授权部门" width="150px" sortable="custom" sort-by="authorizationdeptcodes" align="center" header-align="center"></el-table-column> -->
					<el-table-column prop="authorizationdeptnames" label="授权部门" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="authorizernames" label="授权人员" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<!-- <el-table-column prop="authorizercodes" label="授权人员工号" width="150px" sortable="custom" sort-by="authorizercodes" align="center" header-align="center"></el-table-column> -->
					<el-table-column prop="emails" label="额外提醒邮箱" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="dispdepttype" label="部门类型" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column prop="enabled" label="有效" width="100px" align="center" header-align="center">
						<template slot-scope="scope">
							<el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
							<el-tag v-else type="danger">否</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="操作" width="80px" align="center" fixed="right" v-if="isSingleSelect === true">
						<template slot-scope="scope">
							<el-button type="text" icon="el-icon-finished" @click="doSelectData(scope.row[fieldDefaultKey])">选择</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- 列表分页 -->
				<el-row class="pagebar" ref="pager">
					<el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
				</el-row>
			</div>
		</div>
		<div slot="footer" class="dialog-footer" v-if="isSingleSelect === false">
			<el-button type="text" @click="doCancelEdit">取消</el-button>
			<el-button type="primary" @click="doConfirm">确认</el-button>
		</div>
	</el-dialog>
</template>

<script>
/** mixins */
import { mixin_ref_list } from '@tapui/mixins/mixin_ref_list'
/** 子组件 */
/** 工具类 */
import { queryDataCode } from '@tapui/api/dataCode'
import { getAction, putAction, postAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
	name: 'TlQemDutyDeptRef',
	components: {},
	mixins: [mixin_ref_list],
	data() {
		return {
			description: '维护-责任主体部门配置参照页面',
			// 默认Key字段名
			fieldDefaultKey: 'id',
			// 默认显示字段名
			fieldDefaultValue: 'name',
			// url配置
			url: {
				list: '/qms/qemDutyDept/refList'
			},
			// 排序参数
			sorterInfo: {
				sidx: 'sortcode',
				sord: 'asc'
			},
			enabledList: [],
			deptType: []
		}
	},
	props: {
		// 该参数控制显示是否有效的数据，如果为true，则显示搜索有效的搜索条件，并且默认显示有效
		isShowQryEnabled: {
			type: Boolean,
			default: true
		},
		// 是否为问题归属产品线的打开的参照，如果为true，则显示部门类型的搜索条件，并且默认显示产品线
		isProductline: {
			type: Boolean,
			default: true
		}
	},
	methods: {
		async open() {
			// this.initRef()
			// this.doClearSelected()
			this.selectedRows = []
			this.selectedRowKeys = []
			if (this.isShowQryEnabled) {
				await queryDataCode({ itemCodes: 'CboYesNo' }).then(res => {
					this.enabledList = res.result.CboYesNo
					this.$set(this.queryParam, 'qry_enabled', '1')
				})
			} else {
				this.$set(this.queryParam, 'qry_enabled', '')
			}
			if (this.isProductline) {
				await queryDataCode({ itemCodes: 'QmsDeptType' }).then(res => {
					this.deptType = res.result.QmsDeptType
					this.$set(this.queryParam, 'qry_depttype', '1')
				})
			} else {
				this.$set(this.queryParam, 'qry_depttype', '')
			}
			this.pageInfo.currentPage = 1
			this.pageInfo.totalCount = 0
			this.doQuery()
		},
		clearRef() {
			this.$emit('clearRef')
		}
	}
}
</script>
